package cn.iotab.iotkit.transport.api.common.message;

import cn.iotab.iotkit.queue.queue.DefaultQueueMsgHeaders;
import cn.iotab.iotkit.queue.queue.QueueMsg;
import cn.iotab.iotkit.transport.api.common.util.JsonUtil;

public class JsonQueueMsg<T extends TransportMsg> implements QueueMsg<T> {

    private final String key;
    protected final T value;
    private final QueueMsg.Headers headers;

    public JsonQueueMsg(String key, T value) {
        this(key, value, new DefaultQueueMsgHeaders());
    }

    public JsonQueueMsg(String key, T value, QueueMsg.Headers headers) {
        this.key = key;
        this.value = value;
        this.headers = headers;
    }

    public T getValue(){
        return value;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public QueueMsg.Headers getHeaders() {
        return headers;
    }

    @Override
    public byte[] getData() {
        return JsonUtil.toJsonBytes(value);
    }
}
